package proxy06;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Date;

public class HandlerImpl implements InvocationHandler {
    private LaoWang lw = new LaoWang();
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("被代理的方法是:" + method);
        System.out.println("代理类对象调用方法传递的参数");
        for (Object arg : args) {
            System.out.println(arg);
        }
        System.out.println("------------------");
        Object returnVal = method.invoke(lw, args);//类似: lw.getSum(7,12);
        System.out.println("returnVal=" + returnVal);

        return returnVal;//我们一般把method调用的方法的返回值作为invoke的返回值
    }
}
